home *** CD-ROM | disk | FTP | other *** search
/ MacUser ROM 45 / MACUSER-ROM-VOL-45-1997-08.ISO.7z / MACUSER-ROM-VOL-45-1997-08.ISO / 本誌連動 / 第9回:ウイークエンドデベロッパーへの道 / QuickCinema 1.0 / Source code / Initialize.c next >
Text File  |  1997-03-03  |  4KB  |  134 lines

  1. /*------------------------------------------------------------------------------
  2. *    プログラム名:    QuickCinema 1.0.0
  3. *    ファイル名:        Initialize.c
  4. *-----------------------------------------------------------------------------*/
  5.  
  6. #include "QuickCinema.h"
  7. #include "ProtoType.h"
  8.  
  9. //----------------------------------------------------------------------------------//
  10. //            定数定義                                                                //
  11. //----------------------------------------------------------------------------------//
  12.  
  13. //----------------------------------------------------------------------------------//
  14. //            グローバル変数                                                            //
  15. //----------------------------------------------------------------------------------//
  16.  
  17. extern Boolean                gQuitApplication;
  18. extern Boolean                gIsBackground;
  19. extern SInt32                gSleepTime;
  20. extern AEAddressDesc        gSelfAddress;
  21.  
  22. //----------------------------------------------------------------------------------//
  23. //            プロトタイプ                                                            //
  24. //----------------------------------------------------------------------------------//
  25.  
  26. static Boolean CheckEnvironment(void);
  27. static void InitAppleEventHandlers(void);
  28.  
  29. //----------------------------------------------------------------------------------//
  30. // 初期化ルーチン                                                                    //
  31. //----------------------------------------------------------------------------------//
  32. void InitializeStuff(void)
  33. {
  34.     Handle                    menuBar;
  35.     ProcessSerialNumber        processSrlNumber;
  36.         
  37.     MaxApplZone();
  38.     MoreMasters();
  39.     MoreMasters();
  40.     MoreMasters();
  41.     MoreMasters();
  42.         
  43.     InitGraf(&qd.thePort);
  44.     InitFonts();
  45.     InitWindows();
  46.     InitMenus();
  47.     TEInit();
  48.     InitDialogs(0L);
  49.     
  50.     FlushEvents(everyEvent, 0);
  51.     InitCursor();
  52.  
  53.     if (CheckEnvironment() == false)
  54.     {
  55.         AlertUser(eInvalidEnvironment);
  56.         ExitToShell();
  57.     }
  58.     // Movie Toolboxを初期化する
  59.     EnterMovies();
  60.     
  61.     gQuitApplication = false;
  62.     gIsBackground = false;
  63.     gSleepTime = kSleepTime;
  64.  
  65.      processSrlNumber.highLongOfPSN = 0;
  66.      processSrlNumber.lowLongOfPSN = kCurrentProcess;        
  67.      FailIfErr(AECreateDesc(typeProcessSerialNumber, (Ptr)&processSrlNumber,
  68.                              sizeof(ProcessSerialNumber), &gSelfAddress));
  69.     
  70.     if (!(menuBar = GetNewMBar(rMenuBarResID)))        
  71.     {
  72.         AlertUser(eGoodbyeError);
  73.         ExitToShell();
  74.     }
  75.     SetMenuBar(menuBar);
  76.     DisposeHandle(menuBar);
  77.     AppendResMenu(GetMenuHandle(mApple), kDeskAccessoryType);
  78.     DrawMenuBar();
  79.     
  80.     InitAppleEventHandlers();    
  81. }
  82.  
  83. //----------------------------------------------------------------------------------//
  84. // マックの環境チェック                                                                //
  85. //----------------------------------------------------------------------------------//
  86. static Boolean CheckEnvironment(void)
  87. {
  88.     SInt32                     response;
  89.     OSErr                    err;
  90.  
  91.     err = Gestalt(gestaltSystemVersion, &response);
  92.     response = (response >> 8) & 0xf;                                               
  93.     if ((!err) && (response < 7))
  94.         return false;
  95.  
  96. // QuickTimeがインストール済みであることを確認する
  97. // Power Macintosh環境用
  98. #ifdef powerc
  99.     if (Gestalt(gestaltQuickTime, &response) != noErr)
  100.         return false;
  101.         
  102.     err = Gestalt(gestaltQuickTimeFeatures, &response);
  103.     
  104.     if ((!err) && (response & 1 << gestaltPPCQuickTimeLibPresent))
  105.         return true;
  106.     else
  107.         return false;
  108.  
  109. // 68K Macintosh環境用
  110. #else
  111.     if (Gestalt(gestaltQuickTime, &response) != noErr)
  112.         return false;
  113.     else
  114.         return true;
  115. #endif
  116. }
  117.  
  118. //----------------------------------------------------------------------------------//
  119. // イベントディスパッチテーブル登録                                                    //
  120. //----------------------------------------------------------------------------------//
  121. static void InitAppleEventHandlers(void)
  122. {
  123.     FailIfErr(AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
  124.                         NewAEEventHandlerProc(HandleOpenApplication), 0L, false));
  125.                                 
  126.     FailIfErr(AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
  127.                         NewAEEventHandlerProc(HandleOpenDocument), 0L, false));
  128.     
  129.     FailIfErr(AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
  130.                         NewAEEventHandlerProc(HandleOpenDocument), 0L, false));
  131.  
  132.     FailIfErr(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  133.                         NewAEEventHandlerProc(HandleQuitApplication), 0L, false));
  134. }